package com.alibaba.csp.sentinel.dashboard.rule.apollo;

import com.alibaba.csp.sentinel.util.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName ApolloNameSpaceService
 * @Description TODO
 * @Author zhouchao
 * @Date 2020/3/14 22:35
 * @Version 1.0
 */
@Service
public class ApolloNameSpaceService {

    @Autowired
    private AbstractApolloCommonService abstractApolloCommonService;
    /**
     * 命名空间默认为application
     */
    private static final String defaultNameSpaceName="application";

    /**
     * 根据规则前缀获取Apollo的nameSpaceName
     * @param suffix 规则前缀
     * @return
     */
    public String nameSpace(String suffix){
        String nameSpace = defaultNameSpaceName;
        if (StringUtils.equals(suffix,abstractApolloCommonService.flowDataIdSuffix)){
            nameSpace = abstractApolloCommonService.flowSpaceName;
        }
        if (StringUtils.equals(suffix,abstractApolloCommonService.degradeDataIdSuffix)){
            nameSpace = abstractApolloCommonService.degradeSpaceName;
        }
        if (StringUtils.equals(suffix,abstractApolloCommonService.paramFlowDataIdSuffix)){
            nameSpace = abstractApolloCommonService.paramFlowSpaceName;
        }
        if (StringUtils.equals(suffix,abstractApolloCommonService.systemDataIdSuffix)){
            nameSpace = abstractApolloCommonService.systemSpaceName;
        }
        if (StringUtils.equals(suffix,abstractApolloCommonService.authorityDataIdSuffix)){
            nameSpace = abstractApolloCommonService.authoritySpaceName;
        }
        return nameSpace;
    }
}
